<?php

class AutoShopIdResolve extends CActiveRecordBehavior {
	public function beforeValidate($event) {
		$user = Yii::app()->adminUser;
		$owner = $this->getOwner();
		$shop = Shop::model()->findByAttributes(
				array('worker_id' => $owner->worker_id)
			);
		if($shop && empty($this->owner->shop_id)){
			$this->owner->shop_id = $shop->id;
		}
	}
}

?>